<template>
    <div class="pc-container">
        <Card style="width:320px;">
            <Form ref="loginForm" :model="loginForm" :rules="ruleForm">
                <FormItem prop="user">
                    <Input type="text" v-model="loginForm.user" placeholder="用户名|手机号码">
                        <Icon type="ios-person-outline" slot="prepend"></Icon>
                    </Input>
                </FormItem>
                <FormItem prop="password">
                    <Input type="password" v-model="loginForm.password" placeholder="请输入密码">
                        <Icon type="ios-lock-outline" slot="prepend"></Icon>
                    </Input>
                    <a href="javascript:void(0)" @click="handlerGo('retrievepwd')">找回密码</a>
                    <a href="javascript:void(0)" style="float:right;" @click="handlerGo('register')">注册账号</a>
                </FormItem>
                    <Button :loading="loading" type="primary" style="width:100%;" @click="handleLogin('loginForm')">
                          <span v-if="!loading">登&nbsp;&nbsp;&nbsp;录</span>
                          <span v-else>Loading...</span>
                    </Button>
            </Form>
         </Card>
    </div>
</template>
<script>
    export default {
        data () {
            return {
                loading:false,
                loginForm: {
                    user: '',
                    password: ''
                },
                ruleForm: {
                    user: [
                        { required: true, message: '请输入正确的用户名手机号码', trigger: 'blur' }
                    ],
                    password: [
                        { required: true, message: '请输入正确的密码', trigger: 'blur' },
                        { type: 'string', min: 6, message: '密码长度不能小于6位', trigger: 'blur' }
                    ]
                }
            }
        },
        methods: {
            handleLogin(name) {
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        this.loading=true
                        this.$store.dispatch('login',this.loginForm).then(()=>{
                            this.$router.push({ path: this.redirect || '/', query: this.otherQuery })
                            this.loading=false
                        }).catch(()=>{
                            this.loading=false
                        })
                    } else {
                        this.$Message.error('请输入正确的用户名和密码');
                    }
                })
            },
              handlerGo(row){
            this.$router.push({path:row})
        }
        }
    }
</script>
<style lang="scss" scoped>
    .pc-container{
        .tip{
            padding-top: 5px;
        }
    }
</style>